package site.marqstree.latte.ec.main.personal.order;

import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import butterknife.BindView;
import butterknife.OnClick;
import site.marqstree.latte.core.delegates.LatteDelegate;
import site.marqstree.latte.core.util.callback.CallbackManager;
import site.marqstree.latte.core.util.callback.CallbackType;
import site.marqstree.latte.core.util.callback.IGlobalCallback;
import site.marqstree.latte.ec.R;
import site.marqstree.latte.ec.R2;
import site.marqstree.latte.ui.widget.AutoPhotoLayout;
import site.marqstree.latte.ui.widget.StarLayout;

/*
 * 项目名: EleCommerce
 * 包名: site.marqstree.latte.ec.main.personal.order
 * 文件名: OrderCommentDelegate
 * 创建者: marqstree
 * 创建时间: 2020/2/6 17:36
 * 描述: TODO
 */
public class OrderCommentDelegate extends LatteDelegate {

    @BindView(R2.id.custom_star_layout)
    StarLayout mStarLayout = null;
    @BindView(R2.id.custom_auto_photo_layout)
    AutoPhotoLayout mAutoPhotoLayout = null;
    @BindView(R2.id.img_order_comment)
    ImageView mImgOrder;

    private String mImagUrl;

    public OrderCommentDelegate(String imagUrl) {
        this.mImagUrl = imagUrl;
    }

    private static final RequestOptions OPTIONS = new RequestOptions()
            .centerCrop()
            .diskCacheStrategy(DiskCacheStrategy.NONE);

    @OnClick(R2.id.top_tv_comment_commit)
    void onClickSubmit() {
        Toast.makeText(getContext(), "评分： " + mStarLayout.getStarCount(), Toast.LENGTH_LONG).show();
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_order_comment;
    }


    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {

        Glide.with(this)
                .load(mImagUrl)
                .apply(OPTIONS)
                .into(mImgOrder);

        mAutoPhotoLayout.setDelegate(this);
        CallbackManager.getInstance()
                .addCallback(CallbackType.ON_CROP, new IGlobalCallback<Uri>() {
                    @Override
                    public void executeCallback(@Nullable Uri args) {
                        mAutoPhotoLayout.onCropTarget(args);
                    }
                });
    }
}
